<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<input type="text" id="txt">   
<ul id="uls">

</ul>
<script>
var txt=document.getElementById('txt');
var uls=document.getElementById('uls');
// txt.onkeydown=function(){
//     console.log('按下');
// }
// txt.onkeyup=function(){
//     console.log('松开');
// }
txt.onkeydown=function(e){
    // console.log(e.keyCode); 
    if(e.keyCode==13){
        // console.log('搜素');
        var txtVal=txt.value;
        var lis=document.createElement('li');
        lis.innerHTML=txt.value;
        uls.appendChild(lis);
        txt.value='';
    }   
}
</script>
</body>
</html>